package gespap2009;

public class Ventana extends javax.swing.JFrame {

    private String direccionIntroducida = "";
    private String nombreIntroducido = "";
    private String telefonoIntroducido = "";
    private String correoIntroducido = "";
    private String dniIntroducido = "";
    private ControladorVenta controladorVenta;
    private ControladorClientes controladorClientes;

    /** Creates new form Ventana */
    public Ventana() {
        controladorVenta = ControladorVenta.crearControladorVenta();
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        botonAceptar = new javax.swing.JButton();
        nombreLabel = new javax.swing.JLabel();
        direccionLabel = new javax.swing.JLabel();
        telefonoLabel = new javax.swing.JLabel();
        nombreTextField = new javax.swing.JTextField();
        direccionTextField = new javax.swing.JTextField();
        telefonoTextField = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("GESPAP");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        botonAceptar.setText("Insertar cliente");
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        nombreLabel.setText("Nombre y apellidos");

        direccionLabel.setText("Dirección");

        telefonoLabel.setText("Teléfono");

        nombreTextField.setToolTipText("Introduzca el nombre y apellidos");
        nombreTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                nombreTextFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                nombreTextFieldFocusLost(evt);
            }
        });

        direccionTextField.setToolTipText("Introduzca la dirección");
        direccionTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                direccionTextFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                direccionTextFieldFocusLost(evt);
            }
        });

        telefonoTextField.setToolTipText("Introduzca el teléfono");
        telefonoTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                telefonoTextFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                telefonoTextFieldFocusLost(evt);
            }
        });

        jMenu1.setText("Archivo");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edicion");
        jMenuBar1.add(jMenu2);

        jMenu3.setText("Ayuda");
        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(nombreLabel)
                            .add(direccionLabel)
                            .add(telefonoLabel))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(direccionTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
                            .add(nombreTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
                            .add(telefonoTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)))
                    .add(layout.createSequentialGroup()
                        .add(125, 125, 125)
                        .add(botonAceptar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(37, 37, 37)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(nombreLabel)
                    .add(nombreTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(direccionLabel)
                    .add(direccionTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(telefonoLabel)
                    .add(telefonoTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 95, Short.MAX_VALUE)
                .add(botonAceptar)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        /*Object source = evt.getSource();*/
        /*setTitle ("He cambiado el titulo de la ventana");
        repaint();*/

        System.out.println( "Se ha leido por ventana: " + nombreIntroducido +
                " " + direccionIntroducida + " " + telefonoIntroducido);

        controladorClientes.añadirClienteNuevo(nombreIntroducido, direccionIntroducida,
                telefonoIntroducido, correoIntroducido, dniIntroducido);

        /*if (!telefonoIntroducido.equalsIgnoreCase(""))
            controladorVenta.obtenerCliente(telefonoIntroducido);*/
}//GEN-LAST:event_botonAceptarActionPerformed

    private void nombreTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nombreTextFieldFocusGained
        nombreIntroducido = nombreTextField.getText();
    }//GEN-LAST:event_nombreTextFieldFocusGained

    private void nombreTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nombreTextFieldFocusLost
        nombreTextFieldFocusGained(evt);
    }//GEN-LAST:event_nombreTextFieldFocusLost

    private void direccionTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_direccionTextFieldFocusGained
        direccionIntroducida = direccionTextField.getText();
    }//GEN-LAST:event_direccionTextFieldFocusGained

    private void direccionTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_direccionTextFieldFocusLost
        direccionTextFieldFocusGained(evt);
    }//GEN-LAST:event_direccionTextFieldFocusLost

    private void telefonoTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_telefonoTextFieldFocusGained
        telefonoIntroducido = telefonoTextField.getText();
    }//GEN-LAST:event_telefonoTextFieldFocusGained

    private void telefonoTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_telefonoTextFieldFocusLost
        telefonoTextFieldFocusGained(evt);
    }//GEN-LAST:event_telefonoTextFieldFocusLost

    /**
    * @param args the command line arguments
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Ventana().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JLabel direccionLabel;
    private javax.swing.JTextField direccionTextField;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel nombreLabel;
    private javax.swing.JTextField nombreTextField;
    private javax.swing.JLabel telefonoLabel;
    private javax.swing.JTextField telefonoTextField;
    // End of variables declaration//GEN-END:variables

}
